package com.yunze.web.controller.yunze.install;

import com.alibaba.fastjson.JSON;
import com.yunze.common.utils.ServletUtils;
import com.yunze.common.utils.ip.IpUtils;
import com.yunze.common.utils.yunze.AesEncryptUtil;
import com.yunze.system.service.yunze.install.YzInstallPossessorService;
import com.yunze.web.core.config.MyBaseController;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

/**
 * 住户资料管理
 * @author liuhang
 * @date 2022-6-13
 * */
@Api("住户资料管理")
@RestController
@RequestMapping("/yunze/possessor")
public class YzInstallPossessorController extends MyBaseController {

    @Autowired
    private YzInstallPossessorService yzInstallPossessorService;


    /**
     * 执行 住户资料管理 列表
     * @param Pstr
     * @return
     * */
    @PreAuthorize("@ss.hasPermi('yunze:possessor:list')")
    @PostMapping(value = "/list", produces = {"application/json;charset=UTF-8"})
    public String SynFlow(@RequestBody String Pstr) {
        HashMap<String, Object> Parammap = new HashMap<String, Object>();
        if (Pstr != null) {
            Pstr = Pstr.replace("%2F", "/");//转义 /
        }
        try {
            Pstr = AesEncryptUtil.desEncrypt(Pstr);
            //  System.out.println(map);
            Parammap.putAll(JSON.parseObject(Pstr));
            return MyRetunSuccess(yzInstallPossessorService.PstrMap(Parammap), null);
        } catch (Exception e) {
            String ip = IpUtils.getIpAddr(ServletUtils.getRequest());
            logger.error("<br/> yunze:possessor:list  <br/> Pstr = " + Pstr + " <br/> ip =  " + ip + " <br/> ", e.getCause().toString());
        }
        return Myerr("住户资料管理[列表] 操作失败！");
    }

    /**
     * 执行 住户资料管理 新增
     * @param Pstr
     * @return
     * */
    @PreAuthorize("@ss.hasPermi('yunze:possessor:add')")
    @PostMapping(value = "/add", produces = {"application/json;charset=UTF-8"})
    public String Add(@RequestBody String Pstr) {
        HashMap<String, Object> Parammap = new HashMap<String, Object>();
        if (Pstr != null) {
            Pstr = Pstr.replace("%2F", "/");//转义 /
        }
        try {
            Pstr = AesEncryptUtil.desEncrypt(Pstr);
            //  System.out.println(map);
            Parammap.putAll(JSON.parseObject(Pstr));
            boolean bool = yzInstallPossessorService.add(Parammap);
            if(bool){
                return MyRetunSuccess("操作成功！", null);
            }else {
                return Myerr("新增 住户资料管理 操作失败！");
            }
        } catch (Exception e) {
            String ip = IpUtils.getIpAddr(ServletUtils.getRequest());
            logger.error("<br/> yunze:possessor:add  <br/> Pstr = " + Pstr + " <br/> ip =  " + ip + " <br/> ", e.getCause().toString());
        }
        return Myerr("住户资料管理[新增] 操作失败！");
    }


    /**
     * 执行 住户资料管理 删除
     * @param Pstr
     * @return
     * */
    @PreAuthorize("@ss.hasPermi('yunze:possessor:del')")
    @PostMapping(value = "/del", produces = {"application/json;charset=UTF-8"})
    public String Del(@RequestBody String Pstr) {
        HashMap<String, Object> Parammap = new HashMap<String, Object>();
        if (Pstr != null) {
            Pstr = Pstr.replace("%2F", "/");//转义 /
        }
        try {
            Pstr = AesEncryptUtil.desEncrypt(Pstr);
            //  System.out.println(map);
            Parammap.putAll(JSON.parseObject(Pstr));
            boolean bool = yzInstallPossessorService.del(Parammap);
            if(bool){
                return MyRetunSuccess("操作成功！", null);
            }else {
                return Myerr("删除 操作失败！");
            }
        } catch (Exception e) {
            String ip = IpUtils.getIpAddr(ServletUtils.getRequest());
            logger.error("<br/> yunze:possessor:del  <br/> Pstr = " + Pstr + " <br/> ip =  " + ip + " <br/> ", e.getCause().toString());
        }
        return Myerr("住户资料管理[删除] 操作失败！");
    }

    /**
     * 执行 住户资料管理 修改
     * @param Pstr
     * @return
     * */
    @PreAuthorize("@ss.hasPermi('yunze:possessor:upd')")
    @PostMapping(value = "/upd", produces = {"application/json;charset=UTF-8"})
    public String Upd(@RequestBody String Pstr) {
        HashMap<String, Object> Parammap = new HashMap<String, Object>();
        if (Pstr != null) {
            Pstr = Pstr.replace("%2F", "/");//转义 /
        }
        try {
            Pstr = AesEncryptUtil.desEncrypt(Pstr);
            //  System.out.println(map);
            Parammap.putAll(JSON.parseObject(Pstr));

            boolean bool = yzInstallPossessorService.upd(Parammap);
            if(bool){
                return MyRetunSuccess("操作成功！", null);
            }else {
                return Myerr("修改 操作失败！");
            }
        } catch (Exception e) {
            String ip = IpUtils.getIpAddr(ServletUtils.getRequest());
            logger.error("<br/> yunze:possessor:upd  <br/> Pstr = " + Pstr + " <br/> ip =  " + ip + " <br/> ", e.getCause().toString());
        }
        return Myerr("住户资料管理[修改] 操作失败！");
    }

    /**
     * 查询手机号  是否存在
     * @param Pstr
     * @return
     * */
    @PreAuthorize("@ss.hasPermi('yunze:possessor:phone')")
    @PostMapping(value = "/phone", produces = {"application/json;charset=UTF-8"})
    public String PhoneLinkman(@RequestBody String Pstr) {
        HashMap<String, Object> Parammap = new HashMap<String, Object>();
        if (Pstr != null) {
            Pstr = Pstr.replace("%2F", "/");//转义 /
        }
        try {
            Pstr = AesEncryptUtil.desEncrypt(Pstr);
            //  System.out.println(map);
            Parammap.putAll(JSON.parseObject(Pstr));
            boolean bool = yzInstallPossessorService.phone(Parammap);
            if(bool){
                return MyRetunSuccess("操作成功！",null);
            }else{
                return Myerr("手机号码已存在");
            }
        } catch (Exception e) {
            String ip = IpUtils.getIpAddr(ServletUtils.getRequest());
            logger.error("<br/> yunze:possessor:phone  <br/> Pstr = " + Pstr + " <br/> ip =  " + ip + " <br/> ", e.getCause().toString());
        }
        return Myerr("查询手机号 操作失败！");
    }



}


















